package org.linlinjava.litemall.admin.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.linlinjava.litemall.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.litemall.admin.dto.GoodsAllinone;
import org.linlinjava.litemall.admin.service.AdminGoodsService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.LitemallBase;
import org.linlinjava.litemall.db.domain.LitemallGoods;
import org.linlinjava.litemall.db.service.LitemallBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/admin/base")
@Validated
public class AdminBaseController {
    private final Log logger = LogFactory.getLog(AdminBaseController.class);

    @Autowired
    private LitemallBaseService  litemallBaseService;

    /**
     *
     * @return
     */
    @RequiresPermissions("admin:base:list")
    @RequiresPermissionsDesc(menu = {"基础参数管理", "基础参数"}, button = "查询")
    @GetMapping("/list")
    public Object list() {
   //     List<LitemallBase>   litemallBasess = ;

        return   ResponseUtil.ok(litemallBaseService.selectall())  ;//ResponseUtil.okList(litemallBasess);
    }


    /**
     * 编辑商品
     *

     * @return
     */
    @RequiresPermissions("admin:base:update")
    @RequiresPermissionsDesc(menu = {"基础参数管理", "基础参数管理"}, button = "编辑")
    @PostMapping("/update")
    public Object update(
                         @RequestParam(defaultValue = "0") Integer baseid  ,
                         @RequestParam(defaultValue = "0") String basetext ,
                         @RequestParam(defaultValue = "0") String basedetail ) {


        LitemallBase  litemallBase =new LitemallBase();
        litemallBase.setBaseid(baseid);
        litemallBase.setBasetext(basetext);
        litemallBase.setBasedetail(basedetail);
        return   ResponseUtil.ok(litemallBaseService.updatebyid(litemallBase));
    }



    @GetMapping("/detail")
    public Object detail(@NotNull Integer id) {
        return ResponseUtil.ok(litemallBaseService.selectbyid(id));

    }


    /**
     * 修改版本信息
     *
     * @return
     */
    @RequiresPermissions("admin:base:update")
    @RequiresPermissionsDesc(menu = {"基础参数管理", "修改版本"}, button = "编辑")
    @PostMapping("/updatebanben")
    public Object updatebanben(@RequestBody  LitemallBase  litemallBase ) {
        return   ResponseUtil.ok(litemallBaseService.updatebanben(litemallBase));
    }
    @GetMapping("/download")
    public Object download  () {

        LitemallBase litemallBase= litemallBaseService.selectBylv();

        return ResponseUtil.ok(litemallBase);
    }

}
